<template>
  <!-- 选择渠道 -->
  <div class="left-container" v-loading.fullscreen.lock="loading">
    <el-form
      ref="channelform"
      :model="channelform"
      :rules="rules"
      label-position="left"
      label-width="110px"
      size="mini"
      class="text-sm"
    >
      <el-row :gutter="10">
        <el-col :span="12">
          <!-- 起运地 -->
          <el-form-item label="起运地：" prop="loadingPort">
            <el-tooltip
              class="item"
              content="点击填写可快速搜索"
              effect="light"
              placement="top-end"
            >
              <el-select
                v-model="channelform.loadingPort"
                filterable
                placeholder="请选择"
                @change="checkChannelSearchCriteria"
              >
                <el-option
                  v-for="(item, value) in initMap.shippingAddressMap"
                  :key="value"
                  :label="item"
                  :value="parseInt(value)"
                />
              </el-select>
            </el-tooltip>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <!-- 目的地 -->
          <el-form-item label="目的国家：" prop="countryId">
            <el-tooltip
              class="item"
              content="点击填写可快速搜索"
              effect="light"
              placement="top-end"
            >
              <el-select
                v-model="channelform.countryId"
                filterable
                :disabled="orderType === 'quickOrder' ? true : false"
                placeholder="请选择"
                @change="retrieveAddress('add', 0)"
              >
                <el-option
                  v-for="(item, value) in initMap.countryMap"
                  :key="value"
                  :label="item"
                  :value="parseInt(value)"
                />
              </el-select>
            </el-tooltip>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="12">
          <el-form-item label="实重：" prop="customerActualWeight">
            <el-input
              v-model="channelform.customerActualWeight"
              clearable
              :disabled="true"
              @change="checkChannelSearchCriteria"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="件数：" prop="customerTotalPackages">
            <el-input
              v-model.number="channelform.customerTotalPackages"
              :disabled="true"
              clearable
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="12">
          <el-form-item label="体积：" prop="customerVolume">
            <el-input
              :disabled="true"
              v-model="channelform.customerVolume"
              clearable
              @change="changeCustomerVolume"
            /> </el-form-item
        ></el-col>
        <el-col :span="12"></el-col>
      </el-row>

      <!-- FBA -->
      <el-form-item label="目的仓库类型：" prop="purposeWarehouseType">
        <el-radio-group
          ref="aaa"
          v-model="channelform.purposeWarehouseType"
          @change="retrieveAddress('add', 1)"
        >
          <el-radio
            v-for="(item, value) in initMap.stockTypeMap"
            :key="value"
            :label="parseInt(value)"
          >
            {{ item }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <!-- 其他仓库类型 -->
      <el-row v-if="channelform.purposeWarehouseType === 700" :gutter="10">
        <el-col :span="12">
          <el-form-item label="公司名/个人：" prop="dispatcher">
            <el-input v-model="channelform.dispatcher" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系人：" prop="dispatchLinkMan">
            <el-input v-model="channelform.dispatchLinkMan" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系电话：" prop="dispatchPhone">
            <el-input v-model="channelform.dispatchPhone" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="邮箱：" prop="dispatchEmail">
            <el-input v-model="channelform.dispatchEmail" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            v-if="
              channelform.countryId &&
                [329, 332, 339].includes(channelform.countryId)
            "
            label="州/省："
            prop="dispatchProvince"
          >
            <el-select
              v-model="channelform.dispatchProvince"
              filterable
              placeholder="请选择"
            >
              <el-option
                v-for="item in stateMap[channelform.countryId]"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item v-else label="州/省：" prop="dispatchProvince">
            <el-input v-model="channelform.dispatchProvince" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="城市：" prop="dispatchCity">
            <el-input v-model="channelform.dispatchCity" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="邮编：" prop="dispatchZipCode">
            <el-input
              v-model="channelform.dispatchZipCode"
              clearable
              @input="changeZipCode"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="详细地址：" prop="dispatchAddress">
            <el-input v-model="channelform.dispatchAddress" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="详细地址2：" prop="dispatchAddress2">
            <el-input v-model="channelform.dispatchAddress2" clearable />
          </el-form-item>
        </el-col>
        <!-- <el-form-item>
          <el-button type="text" @click="getUserAddress">
            常用派送地址
          </el-button>
          <el-button type="text" @click="saveUserAddress">
            保存为常用派送地址
          </el-button>
        </el-form-item> -->
      </el-row>

      <!-- 详细地址 -->
      <el-form-item
        v-if="channelform.purposeWarehouseType !== 700"
        label="派送地址："
        prop="dispatchAddressCode"
      >
        <el-tooltip
          class="item"
          content="请先选择目的国家与仓库类型"
          effect="light"
          placement="top-end"
        >
          <el-select
            v-model="channelform.dispatchAddressCode"
            filterable
            placeholder="请选择"
            @change="changeDetailedAddress"
          >
            <template v-if="channelform.purposeWarehouseType !== 400">
              <el-option
                v-for="item in addressList"
                :key="item.id"
                :label="
                  `${item.address}${item.address2 ? ' ' + item.address2 : ''},${
                    item.city
                  },${item.province},${item.zipCode}(${item.fbaCode})`
                "
                :value="item.fbaCode"
              />
            </template>
            <template v-else>
              <el-option
                v-for="item in addressList"
                :key="item.id"
                :label="`${item.fbaCode}`"
                :value="item.fbaCode"
              />
            </template>
          </el-select>
        </el-tooltip>
      </el-form-item>
      <div v-if="[700, 800].includes(channelform.purposeWarehouseType)">
        <el-form-item prop="deliveryNumber">
          <div slot="label">入仓号/入仓预约链接：</div>
          <el-input v-model="channelform.deliveryNumber" clearable />
        </el-form-item>
      </div>
      <el-row
        v-if="publicData.shippingWayMap[channelform.shippingWay] === 'FCL'"
        :gutter="10"
      >
        <el-col :span="12">
          <el-form-item label="柜量：" prop="cabinetNumber">
            <el-input
              v-model.number="channelform.cabinetNumber"
              type="number"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="柜型：" prop="cabinetType">
            <el-select
              v-model="channelform.cabinetType"
              filterable
              placeholder="请选择"
            >
              <el-option
                v-for="item in publicData.cabinetTypeMap"
                :key="item"
                :label="item"
                :value="item"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 渠道能力 -->
      <el-form-item label="渠道能力：" prop="channelCapacity">
        <el-checkbox-group v-model="channelform.channelCapacity">
          <el-checkbox
            v-for="(item, value) in initMap.channelAbilitysMap"
            :key="value.toString()"
            :label="value.toString()"
            name="channelCapacity"
            @change="checkChannelSearchCriteria"
          >
            {{ item }}
          </el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <!-- 特殊产品 -->
      <el-form-item label="特殊产品：" prop="specialProduct">
        <el-checkbox-group
          v-model="channelform.specialProduct"
          @change="changeSpecialProductOptions"
        >
          <el-checkbox
            v-if="initMap.specialProductsMap[53]"
            label="53"
            :disabled="disabledSpecialProduct1"
            name="specialProduct"
          >
            均不是
          </el-checkbox>
          <template v-for="(item, value) in initMap.specialProductsMap">
            <template v-if="item !== '均不是'">
              <el-checkbox
                :key="value.toString()"
                :label="value.toString()"
                :disabled="disabledSpecialProduct2"
                name="specialProduct"
              >
                {{ item }}
              </el-checkbox>
            </template>
          </template>
        </el-checkbox-group>
      </el-form-item>

      <el-row :gutter="10">
        <el-col :span="12">
          <!-- 是否包税 -->
          <el-form-item label="是否包税：" prop="isTaxFarming">
            <el-radio-group
              v-model="channelform.isTaxFarming"
              @change="changeTaxFarming"
            >
              <el-radio
                :disabled="isTaxFarmingDisabled[0]"
                :label="parseInt(1)"
              >
                是
              </el-radio>
              <el-radio
                :disabled="isTaxFarmingDisabled[1]"
                :label="parseInt(0)"
              >
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <!-- 交货条款 -->
          <el-form-item label="交货条款：" prop="deliveryTerms">
            <el-radio-group
              v-model="channelform.deliveryTerms"
              @change="changeDelivery"
            >
              <el-radio :disabled="termsOfDeliveryDisabled[0]" label="DDP">
                DDP
              </el-radio>
              <el-radio :disabled="termsOfDeliveryDisabled[1]" label="DDU">
                DDU
              </el-radio>
            </el-radio-group>
            <el-tooltip class="item" effect="light" placement="right">
              <div slot="content">
                DDU：是指您在目的国自有进口商，且自行支付关税（即：关税到付）；
                <br />DDP：是指您在目的国无进口商，需我司先行垫付关税（即：关税预付）；
                <br />如您选择我司的包税渠道，则交货条款默认DDP。
              </div>
              <i class="el-icon-question icon-question text-yellow" />
            </el-tooltip>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 是否报关 -->
      <el-form-item label="是否报关：" prop="isCustomerDeclaration">
        <el-radio-group
          v-model="channelform.isCustomerDeclaration"
          @change="checkChannelSearchCriteria"
        >
          <el-radio :label="parseInt(1)"> 是 </el-radio>
          <el-radio :label="parseInt(0)"> 否 </el-radio>
        </el-radio-group>
      </el-form-item>

      <!-- 渠道 -->
      <el-form-item label="渠道：" prop="inStockChannel">
        <el-select
          v-model="channelform.inStockChannel"
          filterable
          placeholder="请选择"
          @change="changeChannelFn"
        >
          <el-option
            v-for="(item, value) in customerChannelMap"
            :key="value"
            :label="item"
            :value="parseInt(value)"
          />
        </el-select>
      </el-form-item>

      <!-- 派送方式 -->
      <el-form-item
        v-if="
          publicData.countryMap &&
            channelform.inStockChannel &&
            publicData.channelMap[channelform.inStockChannel] &&
            publicData.channelMap[channelform.inStockChannel].indexOf(
              '美国整柜'
            ) != -1
        "
        label="派送方式："
        prop="deliveryType"
      >
        <el-select
          v-model="channelform.deliveryType"
          filterable
          placeholder="请选择"
        >
          <el-option label="整柜直送" value="0" />
          <el-option label="拆柜派送" value="1" />
        </el-select>
      </el-form-item>

      <!-- 国内分区 -->
      <el-form-item label="国内分区：" prop="provinceId">
        <el-select
          v-model="channelform.provinceId"
          filterable
          clearable
          :disabled="isDisabledProvinceId"
          placeholder="请选择"
          @change="changeProvinceId"
        >
          <el-option
            v-for="(item, value) in provinceNameAndIdMap"
            :key="value"
            :label="item"
            :value="parseInt(value)"
          />
        </el-select>
      </el-form-item>

      <!-- PVA -->
      <el-form-item
        v-if="
          initMap.countryMap &&
            channelform.countryId &&
            initMap.countryMap[channelform.countryId] &&
            initMap.countryMap[channelform.countryId].indexOf('英国') != -1 &&
            channelform.inStockChannel &&
            channelform.isTaxFarming === 0 &&
            (channelform.purposeWarehouseType === 100 ||
              channelform.purposeWarehouseType === 400)
        "
        label="Postponed VAT Accounting/增值税递延："
        prop="isPVA"
        label-width="250px"
      >
        <el-radio-group v-model="channelform.isPVA">
          <el-radio :label="parseInt(1)">是</el-radio>
          <el-radio :label="parseInt(0)">否</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-row class="text-row">
        <el-col :span="13">
          <el-form-item label="预计计费重：">
            <span>{{ finalWeight }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="11" class="text-tips">
          <el-form-item label="预计运费" class="text-right">
            <span>{{ feightMoney }}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 中澳证 -->
      <el-form-item
        label="委托制作中澳证："
        v-if="channelform.countryId == 339 && channelform.isTaxFarming == 0"
        prop="isChinaAustraliaCard"
        label-width="120px"
      >
        <el-radio-group v-model="channelform.isChinaAustraliaCard">
          <el-radio :label="parseInt(1)">是</el-radio>
          <el-radio :label="parseInt(0)">否</el-radio>
        </el-radio-group>
        <el-tooltip class="item" effect="light" placement="right">
          <div slot="content">
            <div style="padding: 5px 10px">
              是否要花费150RMB由九方代做一份中澳证以免目的港的DUTY税费
            </div>
          </div>

          <i class="el-icon-question icon-question text-yellow" />
        </el-tooltip>
      </el-form-item>
      <el-row>
        <el-col :xs="24" :sm="24" :md="24" :lg="13" class="md-100">
          <el-form-item prop="selfDelivered" label="交货方式：">
            <el-radio-group v-model="channelform.selfDelivered">
              <el-radio :label="parseInt(1)">九方提货</el-radio>
              <el-radio :label="parseInt(0)">客户自送</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="11" class="md-100">
          <el-form-item prop="isBuyInsurance" label="是否购买保险：">
            <el-radio-group v-model="channelform.isBuyInsurance">
              <el-popover
                placement="top"
                width="400"
                trigger="hover"
                class="margin-rigth"
              >
                <div>赔偿细则和标准：</div>
                <div>
                  1、甲方按照（产品采购货值+运费）的0.4%向乙方支付保费，最低50RMB/票；
                </div>
                <div>2、按照系统下单时提供的（产品采购货值+运费）赔偿；</div>
                <div>3、免赔额为10%，即只赔偿（产品采购货值+运费）的90%；</div>
                <div class="text-red">4、赔偿上限为RMB800/KG；。</div>

                <el-radio slot="reference" :label="1"
                  ><span class="margin-right">是</span></el-radio
                >
              </el-popover>
              <el-popover placement="top" width="400" trigger="hover">
                <div>赔偿细则和标准：</div>
                <div>1、按照系统下单时提供的（产品采购货值+运费）赔偿；</div>
                <div>2、免赔额为10%，即只赔偿（产品采购货值+运费）的90%；</div>
                <div class="text-red">3、赔偿上限为RMB200/KG。</div>

                <el-radio slot="reference" :label="0">否</el-radio>
              </el-popover>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="text-gray margin-bottom-sm">
        如送货不在预计入仓时间段内，需提前联系对应销售，通知仓库做收货准备
      </div>

      <el-row>
        <el-col :span="12">
          <el-form-item prop="etInStockDay">
            <div slot="label">入仓时间：</div>
            <el-date-picker
              v-model="etInStockDay"
              type="date"
              placeholder="选择日期"
              :picker-options="pickerOptions"
              value-format="yyyy-MM-dd"
              @change="changeEtInStock"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="etInStockTime">
            <el-select
              v-model="etInStockTime"
              placeholder="请选择"
              @change="changeEtInStock"
            >
              <el-option
                v-for="item in timeOptions"
                :key="item"
                :label="item"
                :value="item"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 其他仓库类型 -->
      <el-row
        v-if="channelform.isVatAndEori == 1"
        :gutter="10"
        sytle="margin-top:20px;"
      >
        <el-col :span="12">
          <el-form-item label="进口商：" prop="customerImporterId">
            <el-select
              v-model="channelform.customerImporterId"
              filterable
              placeholder="请选择"
              @change="changeCustomerImporter"
            >
              <el-option
                v-for="(item, value) in initMap.customerImportMap"
                :key="value"
                :label="item"
                :value="parseInt(value)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系人：" prop="importerLinkMan">
            <el-input v-model="channelform.importerLinkMan" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="公司名：" prop="importerCompanyName">
            <el-input v-model="channelform.importerCompanyName" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="电话：" prop="isChangeImportInfo">
            <el-input v-model="channelform.isChangeImportInfo" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="VAT：" prop="vat">
            <el-input v-model="channelform.vat" clearable />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="邮编：" prop="importerZipCode">
            <el-input v-model="channelform.importerZipCode" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="EORI：" prop="eori">
            <el-input v-model="channelform.eori" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="详细地址：" prop="importerAddress">
            <el-input v-model="channelform.importerAddress" clearable />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <div class="dialog-footer margin-top text-right">
      <!-- <el-button type="success" @click="cloeseDialog">
        取消
      </el-button> -->
      <el-button type="primary" @click="changeForecastInfo" size="mini">
        保存
      </el-button>
    </div>
  </div>
</template>

<script>
import { ajax, actionPermission } from "@/store/yg/common/utils";
import { m } from "@/store/yg/common/local";
import { clone } from "@/utils/clone";
import { getState } from "@/utils/getState";
import { Loading } from "element-ui";

export default {
  name: "SelectChannelLeft",
  props: {
    orderType: {
      type: String,
      default: "seaairwaybill"
    },

    centerDialogVisible: {
      type: Boolean,
      default: false
    },
    forecastForm: {
      type: Object,
      default: function() {
        return {};
      }
    },
    Constatvariable: {
      type: Object,
      default: function() {
        return {};
      }
    },
    channelInitMap: {
      type: Object,
      default: function() {
        return {};
      }
    },
    initMap: {
      type: Object,
      default: function() {
        return {};
      }
    }
  },
  data() {
    return {
      timer2: null,
      loading: false,
      stateMap: getState(),
      disabledSpecialProduct1: false, // 特殊产品禁用
      disabledSpecialProduct2: false, // 特殊产品禁用
      pickerOptions: {},
      inputDisabled: false,
      publicData: {
        shippingWayMap: {}
      },
      timeOptions: [
        "09:00-11:00",
        "11:00-13:00",
        "13:00-15:00",
        "15:00-17:00",
        "17:00-19:00",
        "19:00-21:00"
      ],
      shippingWay: "",
      isShowPVA: false,
      isDisabledProvinceId: false, //  禁选国内分区
      finalWeight: 0, //  预计计费重
      feightMoney: 0, //  预计 运费
      selectShippingAddress: false,
      dialogTips: false,
      isTaxFarmingDisabled: [false, false],
      termsOfDeliveryDisabled: [false, false],
      fileList: [],
      addressList: [],
      customerChannelMap: this.channelInitMap,
      customerChannelForm: {},
      provinceNameAndIdMap: {},

      pickupInfo: [], //  派送地址
      channelform: {
        id: "",
        cabinetNumber: "", // 柜量
        cabinetType: "", // 柜型
        purposeWarehouseType: "", //  目的仓库类型
        customerRemark: "", // 运单备注
        //  value: '',
        deliveryNumber: "", // 起运地
        loadingPort: "", // 起运地
        countryId: "", //  国家
        customerActualWeight: "", //  重量
        customerTotalPackages: "", // 件数
        customerVolume: "", //  体积
        dispatchAddressCode: "", // 地址
        channelCapacity: [], //  渠道能力
        specialProduct: [], //  特殊产品
        isTaxFarming: "", // 是否包税
        isChinaAustraliaCard: "", // 中澳证
        deliveryTerms: "", //  交货条款
        isCustomerDeclaration: "", //  是否报关
        provinceId: "", //  国内分区
        inStockChannel: "", //  渠道
        deliveryWay: "", // 提货方式
        isBuyInsurance: "", // 保险
        dispatcher: "", // 公司名/个人
        dispatchLinkMan: "", //  联系人
        dispatchPhone: "", //  联系电话
        dispatchEmail: "", //  邮箱
        dispatchProvince: "", //  省
        dispatchCity: "", //  城市
        dispatchZipCode: "", //  邮编
        dispatchAddress: "", //  地址
        dispatchAddress2: "", //地址2
        shippingWay: "", //  海空运下单方式
        isPVA: "", //  Postponed VAT Accounting/增值税递延
        etInStock: ""
      },
      etInStockDay: "",
      etInStockTime: "",

      //写到外面  否则会报错

      rules: {
        loadingPort: [
          { required: true, message: "请选择起运地", trigger: "change" }
        ],
        countryId: [
          { required: true, message: "请选择目的国家", trigger: "change" }
        ],
        dispatchAddressCode: [
          { required: true, message: "请选择详细地址", trigger: "change" }
        ],
        customerTotalPackages: [
          { required: true, message: "请填写正整数", trigger: "blur" },
          { type: "number", message: "件数必须为数字值" }
        ],
        purposeWarehouseType: [
          { required: true, message: "请选择仓库类型", trigger: "change" }
        ],
        cabinetNumber: [
          { required: true, message: "请填写正整数", trigger: "blur" },
          { type: "number", message: "件数必须为数字值" }
        ],
        isPVA: [{ required: true, message: "请选择PVA", trigger: "change" }],
        cabinetType: [
          { required: true, message: "请选择柜型", trigger: "change" }
        ],

        channelCapacity: [
          {
            type: "array",
            required: true,
            message: "请至少选择一个",
            trigger: "change"
          }
        ],
        specialProduct: [
          {
            type: "array",
            required: true,
            message: "请至少选择一个",
            trigger: "change"
          }
        ],

        isTaxFarming: [
          { required: true, message: "请选择是否包税", trigger: "change" }
        ],
        isChinaAustraliaCard: [
          {
            required: true,
            message: "请选择是否委托制作中澳证",
            trigger: "change"
          }
        ],
        deliveryTerms: [
          { required: true, message: "请选择交货条款", trigger: "change" }
        ],
        isCustomerDeclaration: [
          { required: true, message: "请选择是否报关", trigger: "change" }
        ],
        inStockChannel: [
          { required: true, message: "请选择渠道", trigger: "change" }
        ],
        deliveryType: [
          { required: true, message: "请选择派送方式", trigger: "change" }
        ],
        provinceId: [
          { required: false, message: "请选择国内分区", trigger: "change" }
        ],
        deliveryWay: [
          { required: true, message: "请选择提货方式", trigger: "change" }
        ],
        isBuyInsurance: [
          { required: true, message: "请选择是否购买保险", trigger: "change" }
        ],
        dispatcher: [
          { required: true, message: "请填写公司名", trigger: "blur" }
          // {
          //   pattern: /^[a-zA-Z0-9_\,\.\/\-\s\!\@\#\$\%\^\&\*\(\)]*$/,
          //   message: "请填写英文或者数字"
          // }
        ],

        dispatchLinkMan: [
          { required: true, message: "请填写联系人", trigger: "blur" }
        ],
        dispatchPhone: [
          { required: true, message: "请填写联系方式", trigger: "blur" }
        ],
        dispatchEmail: [
          { required: false, message: "请填写邮箱地址", trigger: "blur" },
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"]
          }
        ],
        dispatchZipCode: [
          { required: true, message: "请填写邮编", trigger: "blur" }
        ],
        dispatchAddress: [
          { required: true, message: "请填写地址", trigger: "blur" }
        ],
        dispatchProvince: [
          { required: true, message: "请填写省", trigger: "change" }
        ],
        dispatchCity: [
          { required: true, message: "请填写城市", trigger: "change" }
        ]
      }
    };
  },
  computed: {},
  watch: {
    forecastForm: {
      handler(newVal, oldVal) {
        if (!this.channelform["isforChange"]) {
          console.log("this.channelform :>> 变化覆盖");
          this.channelform["isforChange"] = 1;
          this.channelform = clone(newVal);
          this.init();
        }
      },
      deep: true,
      immediate: true
    },
    "channelform.provinceId": {
      handler(val, oldVal) {
        console.log("provinceId :>> ", val);
        console.log("provinceId oldVal :>> ", oldVal);
        if (oldVal && oldVal !== val) {
          this.$message.warning(
            `${this.provinceNameAndIdMap[oldVal]} 可能无法为您派送到正确的地址，系统自动为您选择 ${this.provinceNameAndIdMap[val]}`
          );
        }
      },
      deep: true,
      immediate: true
    }
  },
  created() {},
  mounted() {
    this.shipingWay = this.Constatvariable.shippingway;
    const _this = this;
    // 特定邮编
    this.rules.dispatchZipCode = [
      { required: true, message: "请填写邮编" },
      {
        validator: (rule, value, cb) => {
          const reg1 = /^((\d{5})*(-\d{4})|(\d{5}))$/;
          if (
            parseFloat(_this.channelform.countryId) === 329 &&
            !reg1.test(value)
          ) {
            cb(new Error("格式错误，美国邮编请填入XXXXX或者XXXXX-XXXX"));
          } else {
            cb();
          }
        },
        trigger: "blur"
      }
    ];
  },

  methods: {
    async init() {
      if (
        this.Constatvariable["shippingWay"] == "ZX" ||
        this.Constatvariable["shippingWay"] == "AIR"
      ) {
        this.createTpye = "OrderToAirFreight";
      } else if (
        this.Constatvariable["shippingWay"] == "FCL" ||
        this.Constatvariable["shippingWay"] == "LCL"
      ) {
        this.createTpye = "orderToSeaFreight";
      } else {
        this.createTpye = "OrderToExperssFreight";
      }

      var params = {};
      params["id"] = this.Constatvariable["countryId"];
      params["param1"] = this.Constatvariable["purposeWarehouseType"];

      this.provinceNameAndIdMap = this.initMap.provinceNameAndIdMap;
      this.channelform.channelCapacity = this.Constatvariable["abilitys"] || [];
      this.channelform.specialProduct =
        this.Constatvariable["specialProducts"] || [];
      this.channelform.isTaxFarming = this.Constatvariable["isTaxFarming"];
      // await this.loadFbaCodeByCoutry(params);
      this.queryFbaCodeByCoutry(params, "edit");
    },

    changeCustomerImporter() {
      var params = {};
      params["id"] = this.channelform.customerImporterId;
      ajax("fetchCustomerImportInfo", params).then(
        res => {
          if (res.code == 200) {
            this.channelform.importerZipCode = res.data.zipCode;
            this.channelform.importerCompanyName = res.data.importerCompany;
            this.channelform.vat = res.data.vat;
            this.channelform.importerPhone = res.data.importerPhone;
            this.channelform.importerAddress = res.data.importerAddress;
            this.channelform.eori = res.data.eori;
            this.channelform.importerLinkMan = res.data.importerAttn;
            this.channelform.importerPhone = res.data.importerPhone;
          }
        },
        error => {
          console.log(error);
        }
      );
    },
    changeProvinceId(val) {
      console.log("val :>> ", val);

      this.feightMoney =
        this.customerChannelForm.partitionAndCost[
          this.provinceNameAndIdMap[val]
        ] || 0;

      this.channelform.expectFreight = this.feightMoney;

      let flag = false;
      for (const i in this.customerChannelForm.partitionAndCost) {
        if (this.customerChannelForm.partitionAndCost[i]) {
          flag = true;
        }
      }

      if (flag) {
        if (!this.feightMoney) {
          this.$message.error("该分区无相应运费，请重新选择");
        }
      } else {
        if (!this.customerChannelForm.feightMoney) {
          this.$message.error("该渠道与分区无相应运费，请重新选择渠道");
        }
      }
    },
    changeForecastInfo() {
      this.loading = true;
      this.$refs.channelform.validate(valid => {
        if (valid) {
          if (
            (this.channelform.countryId === 339 ||
              this.channelform.countryId === 329 ||
              this.channelform.countryId === 332) &&
            this.channelform.purposeWarehouseType === 700 &&
            this.channelform.dispatchProvince.length > 3
          ) {
            this.$message.error("州/省长度不可以大于3");
          } else {
            this.submitIfno();
          }
        } else {
          this.$message.error("请填写渠道信息");
        }
      });
    },
    trim(str) {
      let result;
      if (str) {
        result = str.replace(/\s/g, ""); // 去除字符串全部空格
      }
      return result ? result : "";
    },
    submitIfno() {
      const shippingway = this.shipingWay;
      this.channelform.shipingWay = shippingway;
      const cf = clone(this.channelform);
      // cf.channelAbility = cf.channelCapacity.toString(); //  渠道能力
      // cf.specialProduct = cf.specialProduct.toString(); //  特殊产品
      // cf.etInStock = this.Constatvariable.shipingWay;
      // this.channelform.etInStockDay + " " + this.channelform.etInStockTime;
      if (
        !(
          this.initMap.countryMap &&
          this.channelform.countryId &&
          this.initMap.countryMap[this.channelform.countryId] &&
          this.initMap.countryMap[this.channelform.countryId].indexOf("英国") !=
            -1 &&
          this.channelform.inStockChannel &&
          this.channelform.isTaxFarming === 0 &&
          (this.channelform.purposeWarehouseType === 100 ||
            this.channelform.purposeWarehouseType === 400)
        )
      ) {
        cf.isPVA = "";
      }
      // 去字符串空格
      let vat = this.trim(cf.vat);
      cf.vat = vat;
      let eori = this.trim(cf.eori);
      cf.eori = eori;
      ajax("changeForecastInfo", cf).then(
        res => {
          this.loading = false;
          if (res.code != 200) {
            if (null != res.message) {
              this.$message.error(m(res.message));
            } else {
              this.$message.error("修改失败!");
            }
          } else {
            this.$message.success("修改成功!");

            this.$emit("saveInfo");
          }
        },
        error => {
          this.loading = false;
          console.log(error);
        }
      );
    },

    //  改变 特殊产品
    changeSpecialProductOptions(e) {
      console.log("e :>> ", e);
      if (e[e.length - 1] === "53") {
        this.channelform.specialProduct = ["53"];
        this.disabledSpecialProduct1 = false;
        this.disabledSpecialProduct2 = true;
      } else {
        const index =
          this.channelform.specialProduct.indexOf("53") ||
          this.channelform.specialProduct.indexOf("-1");
        if (index > -1) {
          this.channelform.specialProduct.splice(index, 1);
        }
        this.disabledSpecialProduct1 = true;
        this.disabledSpecialProduct2 = false;
      }
      if (e.length === 0) {
        this.disabledSpecialProduct1 = false;
        this.disabledSpecialProduct2 = false;
      }

      this.checkChannelSearchCriteria();
    },
    //  改变 是否包税
    changeTaxFarming(e) {
      // 澳大利亚
      if (
        Number(this.channelform.countryId) === 339 &&
        this.channelform.isTaxFarming === 0
      ) {
        this.$set(this.channelform, "isChinaAustraliaCard", 0);
      }
      //  不包税: "38"
      //  包税: "32"
      //  包税时，只可以选择DDP
      if (parseInt(e) === 1) {
        // this.channelform.isVatAndEori = 0
        this.$set(this.channelform, "isVatAndEori", 0);
        this.$set(this.channelform, "isPVA", "");
        this.$set(this.channelform, "deliveryTerms", "DDP");
        this.$set(this.termsOfDeliveryDisabled, 1, true);
      } else {
        this.$set(this.channelform, "isVatAndEori", 1);
        this.$set(this.termsOfDeliveryDisabled, 1, false);
      }
      this.checkChannelSearchCriteria();
    },
    //  改变 交货条款
    changeDelivery(e) {
      //  DDP: "29"
      //  DDU: "28"
      //  交货条款 === DDU 时，只可以选择不包税
      this.forecastForm.deliveryTerms = e;
      console.log("交货条款》》》", e);
      if (e === "DDU") {
        this.$set(this.channelform, "isTaxFarming", 0);
        this.$set(this.isTaxFarmingDisabled, 0, true);
      } else {
        this.$set(this.isTaxFarmingDisabled, 0, false);
      }
      this.checkChannelSearchCriteria();
    },
    //  根据国家 跟 仓库 匹配 地址
    async retrieveAddress(type, num) {
      const cf = this.channelform;

      this.finalWeight = 0; // 计费重
      this.feightMoney = 0; //  预计运费

      if (
        cf.countryId &&
        cf.purposeWarehouseType &&
        cf.purposeWarehouseType !== 700
      ) {
        var params = {};
        params["id"] = cf.countryId;
        params["param1"] = cf.purposeWarehouseType;
        this.queryFbaCodeByCoutry(params, type);
      }

      // 日本
      if (this.isJapan && num === 0) {
        //
        this.$alert(
          '<span>请注意，根据日本海关新规，提供的截图需规范才能目的港正常清关。为保证您的时效，请上传正确的截图。截图规范，详见清关发票处</span> <span class="text-blue pointer">日本海关文件要求</span>',
          "请注意",
          {
            dangerouslyUseHTMLString: true
          }
        );
      }
      // 澳大利亚
      if (
        Number(this.channelform.countryId) === 339 &&
        this.channelform.isTaxFarming === 0
      ) {
        this.$set(this.channelform, "isChinaAustraliaCard", 0);
      }
    },

    async loadFbaCodeByCoutry(param) {
      await ajax("queryFbaCodeByCoutry", param).then(
        res => {
          if (res.code == 200) {
            this.addressList = res.data["shippingFbaStocks"];
          }
        },
        error => {
          console.log(error);
        }
      );
    },

    queryFbaCodeByCoutry(param, type) {
      ajax("queryFbaCodeByCoutry", param).then(
        res => {
          if (res.code != 200) {
            if (null != res.message) {
              this.$message.error(m(res.message));
            } else {
              // this.$message.error("获取国家失败!");
            }
          } else {
            const cf = this.channelform;
            this.addressList = res.data["shippingFbaStocks"];
            var countryName = res.data["countryName"];
            // cf.dispatchAddressCode = "";
            // if (type === "add") {
            this.checkChannelSearchCriteria(type);
            // }
          }
        },
        error => {
          console.log(error);
        }
      );
    },

    // 常用派送地址
    customerdeliveryaddressList(data) {},
    customerdeliveryaddressSave(data) {},

    //  改变体积
    changeCustomerVolume() {
      //  海运下单 添加 体积判断
      if (
        this.createTpye === "orderToSeaFreight" &&
        this.channelform.customerVolume
      ) {
        this.checkChannelSearchCriteria();
      }
    },
    //  查验渠道搜索条件
    checkChannelSearchCriteria(type) {
      const cf = this.channelform;
      console.log("cf :>> ", cf);
      if (
        cf.loadingPort &&
        cf.countryId &&
        cf.customerActualWeight &&
        cf.channelCapacity.length > 0 &&
        cf.specialProduct.length > 0 &&
        cf.deliveryTerms !== "" &&
        cf.isTaxFarming !== ""
      ) {
        this.retrieveChannel(type);
      }
    },
    //  FBA: "31" /非FBA: "48"
    async retrieveChannel(type) {
      if (this.channelform.shippingWay) {
        this.shippingWay = this.channelform.shippingWay;
      }
      const cf = this.channelform;
      let zipCode = "";
      const fbaStockCode =
        cf.purposeWarehouseType === 700 ? "" : cf.dispatchAddressCode;
      if (fbaStockCode) {
        const t = this.addressList.find(
          x => x.fbaCode === cf.dispatchAddressCode
        );
        zipCode = t ? t.zipCode : "";
      } else {
        zipCode = cf.dispatchZipCode;
      }
      const params = {
        channelLoadingPortId: parseInt(cf.loadingPort), //  起运地
        countryId: parseInt(cf.countryId), //  目的国家
        weight: parseFloat(cf.customerActualWeight), //  重量
        volumn: parseFloat(cf.customerVolume), //  体积
        channelAbility: cf.channelCapacity.toString(), //  渠道能力
        specialProduct: cf.specialProduct.toString(), //  特殊产品
        other: `${cf.deliveryTerms === "DDP" ? 29 : 28},${
          cf.isTaxFarming ? 32 : 38
        }`, //  其他属性
        type: 1, //  客户渠道查询：0代表查询，1代表下单
        shipingWay: this.shippingWay,
        customerId: cf.customerId,
        fbaStockCode: fbaStockCode,
        zipCode: zipCode
      };
      //  return

      this.queryInStockChannel(params, type);
    },
    async queryInStockChannel(params, type) {
      if (
        params.shipingWay.indexOf("LCL") != -1 ||
        params.shipingWay.indexOf("FCL") != -1
      ) {
        params.shipingWay = "LCL,FCL";
      } else if (
        params.shipingWay.indexOf("AIR") != -1 ||
        params.shipingWay.indexOf("ZX") != -1
      ) {
        params.shipingWay = "AIR,ZX";
      }
      const res = await ajax("queryInStockChannel", params);
      if (res.code != 200) {
        if (null != res.message) {
          this.$message.error(m(res.message));
        }
        console.log("queryInStockChannel>>>查询失败");
        this.finalWeight = 0; // 计费重
        this.feightMoney = 0; //  预计运费
        this.channelform.customerChargedWeight = 0;
        this.channelform.expectFreight = 0;
        this.customerChannelMap = []; //  渠道列表
        this.provinceNameAndIdMap = []; //  渠道信息列表
      } else {
        const cf = this.channelform;
        const data = res.data;
        console.log("this data", data);
        const data2 = res.data2;
        this.publicData.fbaCodeZipCodeMap = data2;
        if (type !== "edit") {
          this.finalWeight = 0; // 计费重
          this.feightMoney = 0; //  预计运费
          this.channelform.customerChargedWeight = 0;
          this.channelform.expectFreight = 0;
          this.customerChannelMap = []; //  渠道列表
          this.provinceNameAndIdMap = []; //  渠道信息列表
          this.channelform.inStockChannel = "";
        }
        if (data === null || data === "null" || JSON.stringify(data) === "{}") {
          this.$message.error("没有符合的渠道，请重新选择");

          return;
        }

        // this.channelform.inStockChannel = ""; //  渠道
        this.customerChannelMap = data.customerChannelMap;
        this.customerChannelFormMap = data.customerChannelFormMap;
        if (this.channelform.inStockChannel) {
          this.changeChannelFn(parseInt(this.channelform.inStockChannel));
        }
      }
    },
    //  选择渠道
    changeChannelFn(val) {
      const cf = this.channelform;
      //  FBA快捷下单
      // 标准下单
      //  判断是否有派送地址
      if (cf.purposeWarehouseType !== 700 && !cf.dispatchAddressCode) {
        cf.inStockChannel = "";
        this.$message.error("请选择派送地址");
        return;
      }
      if (
        cf.purposeWarehouseType === 700 &&
        (!cf.dispatcher ||
          !cf.dispatchLinkMan ||
          !cf.dispatchPhone ||
          !cf.dispatchProvince ||
          !cf.dispatchCity ||
          !cf.dispatchZipCode ||
          !cf.dispatchAddress)
      ) {
        cf.inStockChannel = "";
        this.$message.error("请填写完整派送地址信息");
        return;
      }

      if (!val) {
        this.$message.error("请重新选择渠道,该渠道value值为空", "danger");
        cf.inStockChannel = "";
        return;
      }
      console.log(
        "this.customerChannelFormMap:>> ",
        this.customerChannelFormMap
      );
      console.log(
        "this.customerChannelFormMap[val] :>> ",
        this.customerChannelFormMap[val]
      );
      if (this.customerChannelFormMap[val]) {
        this.customerChannelForm = this.customerChannelFormMap[val];
        this.channelTips =
          this.customerChannelForm.customerChannel.channelExplain || "空";
        //
        cf.shippingWay = this.publicData.shippingWayMap[
          this.customerChannelFormMap[val].customerChannel.channelType
        ];

        console.log("cf.shippingWay :>> ", cf.shippingWay);
        //  渠道信息
        const map = this.customerChannelFormMap[val].provinceNameAndIdMap;
        const p = {};
        for (const i in map) {
          p[map[i]] = i;
        }
        this.provinceNameAndIdMap = p;
        // this.finalWeight = this.customerChannelFormMap[val].finalWeight
        // this.feightMoney = this.customerChannelFormMap[val].feightMoney
      }
      // 重组国内分区
      console.log("cf.dispatchAddressCodes :>> ", cf.dispatchAddressCode);
      console.log(
        'cf.dispatchAddressCode.indexOf("BHX4-") :>> ',
        cf.dispatchAddressCode.indexOf("BHX4-")
      );
      if (val === 100 && cf.dispatchAddressCode.indexOf("BHX4-") !== -1) {
        this.isDisabledProvinceId = true;
        if (!this.provinceNameAndIdMap["248"]) {
          this.provinceNameAndIdMap["248"] = "BHX4-CV5 9PF";
        }
        cf.provinceId = 248;
        this.feightMoney =
          this.customerChannelForm.partitionAndCost["BHX4-CV5 9PF"] || 0;
        this.channelform.expectFreight =
          this.customerChannelForm.partitionAndCost["BHX4-CV5 9PF"] || 0;
        return;
        //  如果是英国海派-不包税=100   并且派送地址为BHX开头 分区默认选中BHX4
      } else if (val === 100 && cf.dispatchAddressCode.indexOf("BHX4") !== -1) {
        this.isDisabledProvinceId = true;

        if (!this.provinceNameAndIdMap["231"]) {
          this.provinceNameAndIdMap["231"] = "BHX4";
        }
        cf.provinceId = 231;
        console.log("cf.provinceId :>> ", cf.provinceId);
        this.feightMoney =
          this.customerChannelForm.partitionAndCost["BHX4"] || 0;
        this.channelform.expectFreight =
          this.customerChannelForm.partitionAndCost["BHX4"] || 0;
        return;
        //  如果是英国海派-不包税=100   并且派送地址为BHX开头 分区默认选中BHX4
      } else if (val === 85 && cf.dispatchAddressCode.indexOf("DTM2") !== -1) {
        //  如果是德国海派-不包税=85   并且派送地址为DTM开头 分区默认选中DTM2
        this.isDisabledProvinceId = true;
        this.provinceNameAndIdMap["198"] = "DTM2";
        cf.provinceId = 198;

        this.feightMoney =
          this.customerChannelForm.partitionAndCost["DTM2"] || 0;
        this.channelform.expectFreight =
          this.customerChannelForm.partitionAndCost["DTM2"] || 0;
        return;
      } else if (val === 253 && cf.purposeWarehouseType !== 100) {
        cf.provinceId = 344;
        this.feightMoney =
          this.customerChannelForm.partitionAndCost["加拿大海外仓"] || 0;
        this.channelform.expectFreight =
          this.customerChannelForm.partitionAndCost["加拿大海外仓"] || 0;
        return;
      } else {
        if (
          this.isNoEmptyObject(this.customerChannelMap) &&
          this.isNoEmptyObject(this.provinceNameAndIdMap)
        ) {
          this.isDisabledProvinceId = false;
        } else {
          // this.isDisabledProvinceId = true //  无分区可以选
        }
      }
      if (
        this.customerChannelFormMap[val] &&
        this.customerChannelFormMap[val].finalWeight
      ) {
        console.log(this.customerChannelFormMap[val].finalWeight);
        this.finalWeight = this.customerChannelFormMap[val].finalWeight;
      }
      if (cf.purposeWarehouseType === 700 && cf.dispatchZipCode) {
        const zipCodeStartStr = cf.dispatchZipCode.substr(0, 1);
        let dispatchAddressCode = "";
        if (
          zipCodeStartStr === "0" ||
          zipCodeStartStr === "1" ||
          zipCodeStartStr === "2" ||
          zipCodeStartStr === "3"
        ) {
          dispatchAddressCode = "邮编0、1、2、3开头";
        } else if (
          zipCodeStartStr === "4" ||
          zipCodeStartStr === "5" ||
          zipCodeStartStr === "6" ||
          zipCodeStartStr === "7"
        ) {
          dispatchAddressCode = "邮编4、5、6、7开头";
        } else if (zipCodeStartStr === "8" || zipCodeStartStr === "9") {
          dispatchAddressCode = "邮编8、9开头";
        }
        console.log("dispatchAddressCode :>> ", dispatchAddressCode);

        cf.provinceId =
          this.customerChannelForm.provinceNameAndIdMap[dispatchAddressCode] ||
          "";
        cf.provinceId = parseInt(cf.provinceId);

        this.feightMoney =
          this.customerChannelForm.partitionAndCost[dispatchAddressCode] || 0;
        this.channelform.expectFreight =
          this.customerChannelForm.partitionAndCost[dispatchAddressCode] || 0;
        return;
        // this.customerChannelForm.partitionAndCost[dispatchAddressCode]
      }

      console.log("this.provinceNameAndIdMap :>> ", this.provinceNameAndIdMap);

      this.calcFbaExpectFreight();
    },
    isNoEmptyObject(target) {
      const type = typeof target;
      return (
        target !== null && type === "object" && Object.keys(target).length > 0
      );
    },
    //  获取常用派送地址 并展示
    async getUserAddress() {
      if (!this.channelform.countryId) {
        this.$message.error("请选择目的国家！");
        return;
      }
      const data = await customerdeliveryaddressList({
        authorization: getToken()
      });

      this.pickupInfo = data.filter(
        x => x.countryId === parseInt(this.channelform.countryId)
      );
      this.selectShippingAddress = true;
      // console.log('this.pickupInfo', this.pickupInfo)
    },
    //  保存填写的地址信息
    async saveUserAddress() {
      const c = {
        countryId: this.channelform.countryId,
        customerDeliveryCompany: this.channelform.dispatcher,
        customerDeliveryAddressAttn: this.channelform.dispatchLinkMan,
        customerDeliveryAddressPhone: this.channelform.dispatchPhone,
        customerDeliveryAddressEmail: this.channelform.dispatchEmail,
        address: this.channelform.dispatchAddress,
        city: this.channelform.dispatchCity,
        state: this.channelform.dispatchProvince,
        zipCode: this.channelform.dispatchZipCode
      };

      const r = {
        customerDeliveryCompany: "请填写收件人/公司名",
        customerDeliveryAddressAttn: "请填写联系人",
        customerDeliveryAddressPhone: "请填写联系电话",
        address: "请填写详细地址",
        city: "请填写城市",
        state: "请填写州/省",
        countryId: "请选择目的国家",
        zipCode: "请填写邮编"
      };

      for (const i in c) {
        // console.log(i)
        if (!c[i]) {
          this.$message.error(r[i]);
          return;
        }
      }
      this.$store.dispatch("app/toggleDialog", true);

      const data = await customerdeliveryaddressSave(c);
      if (data.code === 200) {
        this.$message({
          message: "保存成功",
          type: "success"
        });
      } else {
        this.$message.error(data.message);
      }
      this.$store.dispatch("app/toggleDialog", false);
    },
    //  单击加效果
    selectCard(index) {
      const time = this.timer;
      clearTimeout(time); //  首先清除计时器
      this.timer = setTimeout(() => {
        // console.log('单击', index)
        for (const i in this.pickupInfo) {
          if (parseInt(i) === index) {
            const flag = this.pickupInfo[index].selectType
              ? this.pickupInfo[index].selectType
              : false;
            this.$set(this.pickupInfo[index], "selectType", !flag);
          } else {
            this.pickupInfo[i].selectType = false;
          }
        }
      }, 300); //  大概时间300ms
    },
    //  双击=> 选择该派送地址
    selectedCard(index) {
      // console.log('双击', index)
      const time = this.timer;
      clearTimeout(time);

      this.selectShippingAddress = false;

      this.channelform.dispatcher = this.pickupInfo[
        index
      ].customerDeliveryCompany;
      this.channelform.dispatchLinkMan = this.pickupInfo[
        index
      ].customerDeliveryAddressAttn;

      this.channelform.dispatchPhone = this.pickupInfo[
        index
      ].customerDeliveryAddressPhone;

      this.channelform.dispatchEmail = this.pickupInfo[
        index
      ].customerDeliveryAddressEmail;

      this.channelform.dispatchAddress = this.pickupInfo[index].address;

      this.channelform.dispatchCity = this.pickupInfo[index].city;
      this.channelform.dispatchProvince = this.pickupInfo[index].state;
      this.channelform.dispatchZipCode = this.pickupInfo[index].zipCode;

      // console.log(this.selectedImporterInfo)
    },

    //  选择并展示常用派送地址
    selectCustomerdeliveryaddress() {
      let index = "";
      for (const i in this.pickupInfo) {
        if (this.pickupInfo[i].selectType) {
          index = i;
        }
      }
      this.selectedCard(index);
    },

    //  更改派送地址 选择FBA仓库地址发生变化,计费重运费重新计算
    changeDetailedAddress(val) {
      this.checkChannelSearchCriteria();
      const cf = this.channelform;
      this.finalWeight = 0; // 计费重
      this.feightMoney = 0; //  预计运费
      if (!cf.inStockChannel) {
        return;
      }
      if (!val) {
        return;
      }
      if (
        cf.inStockChannel === 100 &&
        cf.dispatchAddressCode.indexOf("BHX4") !== -1
      ) {
        this.isDisabledProvinceId = true;
        this.provinceNameAndIdMap["BHX4"] = 231;
        cf.provinceId = 231;
        // cf.dispatchAddressCode = "BHX4";
        //  如果是英国海派-不包税=100   并且派送地址为BHX开头 分区默认选中BHX4
      } else if (
        cf.inStockChannel === 85 &&
        cf.dispatchAddressCode.indexOf("DTM2") !== -1
      ) {
        //  如果是德国海派-不包税=85   并且派送地址为DTM开头 分区默认选中DTM2
        this.isDisabledProvinceId = true;
        this.provinceNameAndIdMap["DTM2"] = 198;
        cf.provinceId = 198;
        // cf.dispatchAddressCode = "DTM2";
      }
      console.log(
        "this.customerChannelFormMap :>> ",
        this.customerChannelFormMap
      );
      console.log("cf.inStockChannel :>> ", cf.inStockChannel);
      if (!this.customerChannelFormMap[cf.inStockChannel]) {
        return;
      }
      //  客户计费重重置
      this.finalWeight = this.customerChannelMap.finalWeight;
      this.calcFbaExpectFreight();
    },
    isNoEmptyObject(target) {
      const type = typeof target;
      return (
        target !== null && type === "object" && Object.keys(target).length > 0
      );
    },
    getFindKey(value, obj, me) {
      let objlist = JSON.parse(JSON.stringify(obj));
      delete objlist.me;
      let findKey = (value, compare = (a, b) => a === b) => {
        return Object.keys(objlist).find(k => compare(objlist[k], value));
      };
      return findKey(value);
    },
    /**
     * @description: 计算FBA预计运费
     * @param {*}
     * @return {*}
     */
    calcFbaExpectFreight() {
      console.log("计算FBA预计运费 :>> ", 1);

      this.feightMoney = 0;
      this.channelform.expectFreight = 0;

      const cf = this.channelform;
      console.log("cf.dispatchAddressCode :>> ", cf.dispatchAddressCode);

      this.finalWeight = this.customerChannelForm.finalWeight;
      this.channelform.customerChargedWeight = this.customerChannelForm.finalWeight;

      if (
        cf.dispatchAddressCode === undefined ||
        cf.dispatchAddressCode === "" ||
        cf.dispatchAddressCode === null
      ) {
        return;
      }
      console.log("this.customerChannelForm :>> ", this.customerChannelForm);
      if (this.customerChannelForm === null) {
        return;
      }

      if (this.orderType === "quickOrder") {
        cf.purposeWarehouseType = 100;
      }

      let expectFreight;
      const countryName = this.initMap.countryMap[cf.countryId];
      let dispatchAddressCode = cf.dispatchAddressCode;
      const partitionAndCost = this.customerChannelForm.partitionAndCost; //  分区运费信息

      console.log("partitionAndCost :>> ", partitionAndCost);
      //  分区运费域为空,取国家运费
      if (partitionAndCost === null) {
        expectFreight = this.customerChannelForm.feightMoney;
        //  无分区
        cf.provinceId = "";
        this.feightMoney = expectFreight;
        this.channelform.expectFreight = expectFreight;
        return;
      }

      // let provinceId = this.publicData.countryStateProvinceMap[
      //   dispatchAddressCode
      // ]
      let provinceId = this.getFindKey(
        dispatchAddressCode,
        this.provinceNameAndIdMap
      );
      // console.log('provinceId :>> ', provinceId)
      console.log("dispatchAddressCode :>> ", dispatchAddressCode);
      console.log("partitionAndCost :>> ", partitionAndCost);
      //  分区为FBA仓库代码
      if (partitionAndCost && dispatchAddressCode in partitionAndCost) {
        expectFreight = partitionAndCost[dispatchAddressCode];
        if (provinceId) {
          console.log("provinceId :>> ", provinceId);
          cf.provinceId = parseInt(provinceId);
        }
        this.feightMoney = expectFreight;
        this.channelform.expectFreight = expectFreight;
        return;
      }
      console.log("countryName :>> ", countryName);
      if (countryName.indexOf("美国") > -1) {
        //  根据FBACode取得邮编信息
        if (cf.purposeWarehouseType === 100) {
          if (dispatchAddressCode in this.publicData.fbaCodeZipCodeMap) {
            const fbaCodeZipCode = this.publicData.fbaCodeZipCodeMap[
              dispatchAddressCode
            ].zipCode;

            console.log("fbaCodeZipCode :>> ", fbaCodeZipCode);
            if (fbaCodeZipCode && fbaCodeZipCode.length > 1) {
              const zipCodeStartStr = fbaCodeZipCode.substr(0, 1);
              if (
                zipCodeStartStr === "0" ||
                zipCodeStartStr === "1" ||
                zipCodeStartStr === "2" ||
                zipCodeStartStr === "3"
              ) {
                dispatchAddressCode = "邮编0、1、2、3开头";
              } else if (
                zipCodeStartStr === "4" ||
                zipCodeStartStr === "5" ||
                zipCodeStartStr === "6" ||
                zipCodeStartStr === "7"
              ) {
                dispatchAddressCode = "邮编4、5、6、7开头";
              } else if (zipCodeStartStr === "8" || zipCodeStartStr === "9") {
                dispatchAddressCode = "邮编8、9开头";
              }
              expectFreight = partitionAndCost[dispatchAddressCode];
            }
          }
        } else {
          expectFreight = partitionAndCost[dispatchAddressCode];
        }
      } else if (
        countryName.indexOf("加拿大") > -1 &&
        dispatchAddressCode.length > 3
      ) {
        dispatchAddressCode = dispatchAddressCode.substr(0, 3);
        if (dispatchAddressCode === "YVR") {
          dispatchAddressCode = "加拿大YVR";
        } else if (dispatchAddressCode === "YYZ") {
          dispatchAddressCode = "加拿大YYZ";
        } else if (dispatchAddressCode === "YYC") {
          dispatchAddressCode = "加拿大YYC";
        }
        expectFreight = partitionAndCost[dispatchAddressCode];
      } else if (countryName.indexOf("澳大利亚") > -1) {
        //  是否FBA仓
        if (cf.purposeWarehouseType === 100) {
          dispatchAddressCode = "FBA仓";
        } else {
          dispatchAddressCode = "商业地址&海外仓";
        }
        expectFreight = partitionAndCost[dispatchAddressCode];
      }

      // provinceId = this.countryStateMap[dispatchAddressCode]
      provinceId = this.getFindKey(
        dispatchAddressCode,
        this.provinceNameAndIdMap
      );

      if (provinceId) {
        cf.provinceId = parseInt(provinceId);
        this.isDisabledProvinceId = true;
      }

      if (
        expectFreight === undefined ||
        expectFreight === null ||
        expectFreight === ""
      ) {
        expectFreight = this.customerChannelForm.feightMoney; //  取国家运费

        this.isDisabledProvinceId = false;

        //  判断下单模式 quickOrder/快捷下单
        if (this.orderType === "quickOrder") {
          this.$message.error(
            "该派送地址无相应运费请刷新重新上传入库装箱单计划"
          );
          cf.dispatchAddressCode = "";
        } else if (cf.provinceId) {
          this.changeProvinceId(cf.provinceId);
        } else {
          this.$message.error("未找到运单运费，请选择国内分区");
          //  $('#dispatchAddressCode').select2('val', '')
          // this.isDisabledProvinceId = true
          cf.dispatchZipCode = "";
        }
        //
        return;
      }
      //  预计运费
      this.feightMoney = expectFreight;
      this.channelform.expectFreight = expectFreight;
    },
    changeEtInStock() {
      const cf = this.channelform;
      console.log("cf.etInStockDay :>> ", this.etInStockDay);
      if (this.etInStockDay && this.etInStockTime) {
        this.$delete(cf, "etInStock");
        this.$set(
          cf,
          "etInStock",
          this.etInStockDay + " " + this.etInStockTime
        );
      } else {
        this.$delete(cf, "etInStock");
        this.$set(cf, "etInStock", "");
      }
    },
    changeZipCode() {
      if (this.timer2) {
        clearTimeout(this.timer2);
      }
      this.timer2 = setTimeout(() => {
        this.checkChannelSearchCriteria();
      }, 1000);
    }
  }
};
</script>

<style lang="scss" scoped>
.icon-question {
  font-size: 18px;
  //  vertical-align: text-top;
  margin-left: 10px;
}

.icon-absolute {
  position: absolute;
  right: -24px;
  font-size: 18px;
  top: 50%;
  margin-top: -9px;
}
ul {
  list-style: none;

  li {
    margin-bottom: 12px;
  }
}

.el-input,
.el-select {
  width: 100%;
}
</style>
<style lang="scss">
.text-tips {
  color: red;
  .el-form-item__label {
    color: red;
  }
}

.left-container {
  .text-row {
    .el-form-item__content {
      font-size: 12px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  .el-upload {
    text-align: left;
  }
}
.text-right {
  .el-form-item__content {
    text-align: left;
  }
}

.card-main {
  padding: 20px 20px 0;
  position: relative;
  &:not(:last-child) {
    margin-bottom: 20px;
  }
  .el-form .el-form-item--mini.el-form-item,
  .el-form .el-form-item--small.el-form-item {
    margin-bottom: 0;
  }
}
.el-card.is-always-shadow.selectCart {
  box-shadow: 0 2px 12px 0 rgba(67, 201, 162, 1);
}
@media screen and (min-width: 1200px) {
  .text-right {
    .el-form-item__label {
      text-align: right;
    }
  }
}
</style>
